require "class"
require "util"

User = class("User")

User.maxId = 0

function User:ctor(username, password, id)
    self.username = username
    self.password = password
    -- 自增主键作为id
    if id == nil then
        self.id = User.maxId
        User.maxId = User.maxId + 1
    else
        self.id = tonumber(id)
    end
end

function User:newByString(input)
    local pams = split(input, "|")
    return User.new(pams[1], pams[2], pams[3])
end

function User:simple()
    return {
        username = self.username,
        password = self.password,
        id = self.id
    }
end

function User:__tostring()
    return self.username .. "|" .. self.password .. "|" .. self.id
end
